using System;
using System.Web.Optimization;

namespace DiscoArguments.Web.Client
{
    public class DurandalBundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.IgnoreList.Clear();
            AddDefaultIgnorePatterns(bundles.IgnoreList);

            // HACK: This is currently needed, because datajs is not loadable as AMD module on demand!
            bundles.Add(
                new ScriptBundle("~/Scripts/vendor")
                    .Include("~/Scripts/jquery-{version}.js")
                    .Include("~/Scripts/jquery-ui-{version}.js")
                    .Include("~/Scripts/bootstrap.js")
                    .Include("~/Scripts/knockout-{version}.js")
                    .Include("~/Scripts/knockout.mapping-{version}.js")
                    .Include("~/Scripts/datajs-{version}.js")
                    .Include("~/Scripts/jaydata.js")
                    .Include("~/Scripts/jaydataproviders/oDataProvider.js")
                  );

            // HACK: This is currently needed, because disco is not fully AMD compatible yet!
            bundles.Add(
                new ScriptBundle("~/Scripts/disco")
                    .Include("~/Scripts/disco/disco.ontology.js")
                    .Include("~/Scripts/disco/disco.js")
                  );

            bundles.Add(
                new StyleBundle("~/Content/css")
                    .Include("~/Content/ie10mobile.css")
                    .Include("~/Content/bootstrap.min.css")
                    .Include("~/Content/bootstrap-responsive.min.css")
                    .Include("~/Content/font-awesome.min.css")
                    .Include("~/Content/durandal.css")
                    .Include("~/Content/starterkit.css")
                  );

            bundles.Add(
                new StyleBundle("~/Content/css/app")
                    .Include("~/Content/app/default.css")
                );
        }

        public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
        {
            if (ignoreList == null)
            {
                throw new ArgumentNullException("ignoreList");
            }

            ignoreList.Ignore("*.intellisense.js");
            ignoreList.Ignore("*-vsdoc.js");
            ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
            //ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
            //ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
        }
    }
}